package com.sunspring.zdcall.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;


/**
 * json序列化
 * @Author WuLei
 * @Date 2018/11/28  10:34
 */
@Slf4j
public class JsonUtil {

    private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    /**
     * java对象转Json
     * @param value Object
     * @return json
     */
    public static String write(Object value){
        String json = null;
        try{
            json =  OBJECT_MAPPER.writeValueAsString(value);
        }catch (JsonProcessingException ex) {
            log.error("json序列化错误，源数据{}",value);
        }
        return json;
    }

    public static void main(String[] args) throws Exception {
        String json = "{\"departmentId\":\"6\",\"departmentName\":\"asd\",\"deptDisplayName\":null,\"departmentIntroduction\":null}";
    }

}
